home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / programming / wimpwindow / Source`1,0 < prev    next >
Encoding:
Text File  |  1997-02-04  |  21.9 KB  |  471 lines

  1. App  WimpWindow
  2. In   -
  3. Out  WimpWin
  4. Type Module
  5. Ver  1.02g
  6.  
  7. Define Module
  8.  Name      WimpWindow
  9.  Author    Justin Fletcher
  10.  SWIs
  11.   Prefix   WimpWindow
  12.   Base     &90340
  13.    0       Colour            swi_colour
  14.    1       TitleFlags        swi_titleflags
  15.    2       WorkFlags         swi_workflags
  16.    3       SpriteArea        swi_spritearea
  17.    4       MinWidth          swi_minwidth
  18.    5       MinHeight         swi_minheight
  19.    6       TitleData         swi_titledata
  20.    7       WindowFlags       swi_windowflags
  21.  End SWIs
  22.  Workspace 4
  23.  Init      init
  24. End Module
  25.  
  26. Pre
  27.  #Cond AllowExternal Do you want external tasks to access windows
  28. End Pre
  29.  
  30. #REM Off
  31. ; *******************************************************************
  32. ; Subroutine:   init
  33. ; Description:  Check the RO version and create an offset for the
  34. ;               later ones
  35. ; Parameters:   none
  36. ; Returns:      none
  37. ; *******************************************************************
  38. .init
  39.    STMFD   (sp)!,{r0-r5,link}            ; Stack registers
  40.    XSWI    "OS_Module",18,^$`name
  41.    LDR     r1,[r3,#&14]                  ; offset to help string
  42.    ADD     r1,r1,r3                      ; pointer to help string
  43. $textloop
  44.    LDRB    r0,[r1],#1                    ; read byte and increment
  45.    CMP     r0,#9                         ; until we get to a tab
  46.    BNE     $textloop                     ; go around again
  47.    LDRB    r0,[r1,#2]                    ; read the sub version ie #.x#
  48.    CMP     r0,#ASC("6")                  ; is this version 3.6x ?
  49.                                          ; this will die when ro4 comes out!
  50.    MOVGE   r0,#8                         ; offset of 8
  51.    MOVLT   r0,#0                         ; no offset
  52.    STR     r0,[r12]                      ; store in private space
  53.    LDMFD   (sp)!,{r0-r5,pc}              ; Return from call
  54.  
  55. $`name
  56.    EQUZA   "WindowManager"
  57.  
  58. ; *******************************************************************
  59. ; Subroutine:   check_r0_valid
  60. ; Description:  Checks that r0 is a valid window handle
  61. ; Parameters:   r0-> window handle
  62. ; Returns:      VS and r0-> error block if invalid
  63. ; *******************************************************************
  64. .check_r0_valid
  65.    STMFD   (sp)!,{r0-r2,link}            ; Stack registers
  66.    AND     r1,r0,#3                      ; read bottom two bytes
  67.    CMP     r1,#1                         ; is b0 set ?
  68.    BNE     $notb0                        ; if not, claim it's not a window
  69.    BIC     r0,r0,#1                      ; clear b0
  70.    LDR     r1,[r0]                       ; read first word
  71.    LDR     r2,$`wind                     ; read marker
  72.    CMP     r1,r2                         ; is it really a window ?
  73.    BNE     $notawindow                   ; if not, bounce out
  74. ; check the DomainID if not external tasks
  75. #Cond Of AllowExternal
  76. #Cond Else
  77.    LDR     r1,[r0,#4]                    ; read DomainId
  78.    LMOV    r2,#&FF8                      ; address of DomainId
  79.    LDR     r2,[r2]                       ; read current DomainId
  80. ;    REM     "Owner %&1, Us %&2"
  81.    CMP     r1,r2                         ; are they the same ?
  82.    BNE     $notyourwindow                ; if not, push off
  83. #Cond End
  84.    LDMFD   (sp)!,{r0-r2,pc}              ; Return from call
  85. $`wind
  86.    EQUS    "Wind"                        ; marker for window start
  87. $notb0
  88.    ADR     r0,$`notb0                    ; error block
  89. $error
  90.    ADD     sp,sp,#4                      ; skip r0
  91.    LDMFD   (sp)!,{r1-r2,link}            ; Return from call
  92.    ORRS    pc,link,#vbit                 ; exit with V set
  93. $`notb0
  94.    EQUD    &400C1
  95.    EQUZA   "That is not a window - b0 not set"
  96.  
  97. $notawindow
  98.    ADR     r0,$`notawindow               ; error block
  99.    B       $error                        ; process error
  100. $`notawindow
  101.    EQUD    &400C1
  102.    EQUZA   "That is not a window - Window marker not present"
  103.  
  104. #Cond Of AllowExternal
  105. #Cond Else
  106. $notyourwindow
  107.    ADR     r0,$`notyourwindow            ; error block
  108.    B       $error                        ; process error
  109. $`notyourwindow
  110.    EQUD    &400C1
  111.    EQUZA   "That window does not belong to you"
  112. #Cond End
  113.  
  114. ; *******************************************************************
  115. ; Subroutine:   swi_colour
  116. ; Description:  Sets the colour of a part of the window
  117. ; Parameters:   r0-> window handle
  118. ;               r1 = region
  119. ;                    0 - frame foreground (&FF for none)
  120. ;                    1 - frame background
  121. ;                    2 - work foreground
  122. ;                    3 - work background (&FF for none)
  123. ;                    4 - scrollbar outer
  124. ;                    5 - scrollbar inner
  125. ;                    6 - when focused
  126. ;               r2 = colour
  127. ; Returns:      none, or VS and r0 if error
  128. ; *******************************************************************
  129. .swi_colour
  130.    STMFD   (sp)!,{r0-r2,link}            ; Stack registers
  131.    BL      check_r0_valid                ; is the window handle valid ?
  132.    BVS     $exit                         ; if not, exit with error
  133.    CMP     r1,#0                         ; is this too low ?
  134.    BLT     $error                        ; if so, tell them
  135.    CMP     r1,#6                         ; is this too high ?
  136.    BGT     $error                        ; if so, tell them
  137.    BIC     r0,r0,#1                      ; clear b0
  138.                                          ; **** RO Specific bit ****
  139.    LDR     link,[r12]                    ; read offset for RO version
  140.    ADD     r0,r0,link                    ; and add it to our pointer
  141.                                          ; **** RO Specific bit ****
  142.    ADD     r1,r0,r1                      ; add on the offset we're given
  143.    STRB    r2,[r1,#72+32]                ; store colour in block
  144.    LDR     r1,[sp,#4]                    ; read the colour we changed
  145.    CMP     r1,#2                         ; was it workarea fore ?
  146.    CMPNE   r1,#3                         ; was it workarea back ?
  147.    BEQ     $workarea_redraw              ; if so, redraw it
  148.    BL      redraw_tools                  ; redraw the tools
  149. $exit
  150.    XLDMFD  (sp)!,{r0-r2,pc}              ; Return from call
  151. $workarea_redraw
  152.    BL      redraw_window                 ; redraw the whole window
  153.    B       $exit                         ; and exit nicely
  154. $error
  155.    LDMFD   (sp)!,{r0-r2,link}            ; restore registers
  156.    ADR     r0,$`error                    ; error block
  157.    ORRS    pc,link,#vbit                 ; return with VSet
  158. $`error
  159.    EQUD    &400C1
  160.    EQUZA   "Tool type out of range"
  161.  
  162. ; *******************************************************************
  163. ; Subroutine:   swi_titleflags
  164. ; Description:  Change the current title bar flags
  165. ; Parameters:   r0-> window handle
  166. ;               r1 = BIC value
  167. ;               r2 = EOR value
  168. ; Returns:      none, or VS and r0 if error
  169. ; *******************************************************************
  170. .swi_titleflags
  171.    STMFD   (sp)!,{r0-r3,link}            ; Stack registers
  172.    BL      check_r0_valid                ; is the window handle valid ?
  173.    BVS     $exit                         ; if not, exit with error
  174.    BIC     r0,r0,#1                      ; clear b0
  175.                                          ; **** RO Specific bit ****
  176.    LDR     link,[r12]                    ; read offset for RO version
  177.    ADD     r0,r0,link                    ; and add it to our pointer
  178.                                          ; **** RO Specific bit ****
  179.    LDR     r3,[r0,#72+56]                ; read the current settings
  180.    BIC     r3,r3,r1                      ; clear bits specified
  181.    EOR     r3,r3,r2                      ; and invert those others wanted
  182.    TST     r3,#(1<<6)                    ; is it anti-aliased ?
  183.    BICEQ   r3,r3,#(255<<24)              ; if so, clear top bits
  184.    BIC     r3,r3,#(255<<16)              ; clear top-mid bits
  185.    BIC     r3,r3,#(15<<12)               ; clear icon type
  186.    BIC     r3,r3,#(%10100100)            ; clear the bottom ignored bits
  187.    STR     r3,[r0,#72+56]                ; store back in block
  188.    BL      redraw_tools                  ; redraw the tools
  189. $exit
  190.    XLDMFD  (sp)!,{r0-r3,pc}              ; Return from call
  191.  
  192.  
  193. ; *******************************************************************
  194. ; Subroutine:   swi_workflags
  195. ; Description:  Change the work area button flags
  196. ; Parameters:   r0-> window handle
  197. ;               r1 = BIC value
  198. ;               r2 = EOR value
  199. ; Returns:      none, or VS and r0 if error
  200. ; *******************************************************************
  201. .swi_workflags
  202.    STMFD   (sp)!,{r0-r3,link}            ; Stack registers
  203.    BL      check_r0_valid                ; is the window handle valid ?
  204.    BVS     $exit                         ; if not, exit with error
  205.    BIC     r0,r0,#1                      ; clear b0
  206.                                          ; **** RO Specific bit ****
  207.    LDR     link,[r12]                    ; read offset for RO version
  208.    ADD     r0,r0,link                    ; and add it to our pointer
  209.                                          ; **** RO Specific bit ****
  210.    LDR     r3,[r0,#72+60]                ; read the current settings
  211.    BIC     r3,r3,r1                      ; clear bits specified
  212.    EOR     r3,r3,r2                      ; and invert those others wanted
  213.    AND     r3,r3,#(15<<12)               ; leave just button flags
  214.    STR     r3,[r0,#72+60]                ; store back in block
  215. $exit
  216.    XLDMFD  (sp)!,{r0-r3,pc}              ; Return from call
  217.  
  218.  
  219. ; *******************************************************************
  220. ; Subroutine:   swi_spritearea
  221. ; Description:  Change the sprite area
  222. ; Parameters:   r0-> window handle
  223. ;               r1-> new area
  224. ; Returns:      none, or VS and r0 if error
  225. ; *******************************************************************
  226. .swi_spritearea
  227.    STMFD   (sp)!,{r0-r1,link}            ; Stack registers
  228.    BL      check_r0_valid                ; is the window handle valid ?
  229.    BVS     $exit                         ; if not, exit with error
  230.    BIC     r0,r0,#1                      ; clear b0
  231.                                          ; **** RO Specific bit ****
  232.    LDR     link,[r12]                    ; read offset for RO version
  233.    ADD     r0,r0,link                    ; and add it to our pointer
  234.                                          ; **** RO Specific bit ****
  235.    STR     r1,[r0,#72+64]                ; store in block
  236.    BL      redraw_window                 ; redraw the whole window
  237. $exit
  238.    XLDMFD  (sp)!,{r0-r1,pc}              ; Return from call
  239.  
  240.  
  241. ; *******************************************************************
  242. ; Subroutine:   swi_minwidth
  243. ; Description:  Change the minimum width
  244. ; Parameters:   r0-> window handle
  245. ;               r1-> min width
  246. ; Returns:      none, or VS and r0 if error
  247. ; *******************************************************************
  248. .swi_minwidth
  249.    STMFD   (sp)!,{r0-r2,link}            ; Stack registers
  250.    BL      check_r0_valid                ; is the window handle valid ?
  251.    BVS     $exit                         ; if not, exit with error
  252.    BIC     r0,r0,#1                      ; clear b0
  253.                                          ; **** RO Specific bit ****
  254.    LDR     link,[r12]                    ; read offset for RO version
  255.    ADD     r0,r0,link                    ; and add it to our pointer
  256.                                          ; **** RO Specific bit ****
  257.    LDR     r2,[r0,#72+68]                ; read current word
  258.    BIC     r2,r2,#(255)                  ; clear bottom bits
  259.    BIC     r2,r2,#(255<<8)               ; clear bottom other bits
  260.    BIC     r1,r1,#(255<<16)              ; clear mid bits
  261.    BIC     r1,r1,#(255<<24)              ; clear top bits
  262.    ORR     r1,r1,r2                      ; merge
  263.    STR     r1,[r0,#72+68]                ; store in block
  264.    BL      redraw_open                   ; redraw the window by opening
  265. $exit
  266.    XLDMFD  (sp)!,{r0-r2,pc}              ; Return from call
  267.  
  268. ; *******************************************************************
  269. ; Subroutine:   swi_minheight
  270. ; Description:  Change the minimum height
  271. ; Parameters:   r0-> window handle
  272. ;               r1-> max width
  273. ; Returns:      none, or VS and r0 if error
  274. ; *******************************************************************
  275. .swi_minheight
  276.    STMFD   (sp)!,{r0-r2,link}            ; Stack registers
  277.    BL      check_r0_valid                ; is the window handle valid ?
  278.    BVS     $exit                         ; if not, exit with error
  279.    BIC     r0,r0,#1                      ; clear b0
  280.                                          ; **** RO Specific bit ****
  281.    LDR     link,[r12]                    ; read offset for RO version
  282.    ADD     r0,r0,link                    ; and add it to our pointer
  283.                                          ; **** RO Specific bit ****
  284.    LDR     r2,[r0,#72+68]                ; read current word
  285.    BIC     r2,r2,#(255<<16)              ; clear mid bits
  286.    BIC     r2,r2,#(255<<24)              ; clear top bits
  287.    ORR     r1,r2,r1,LSL #16              ; merge
  288.    STR     r1,[r0,#72+68]                ; store in block
  289.    BL      redraw_open                   ; redraw the window by opening
  290. $exit
  291.    XLDMFD  (sp)!,{r0-r2,pc}              ; Return from call
  292.  
  293. ; *******************************************************************
  294. ; Subroutine:   swi_titledata
  295. ; Description:  Change the titledata
  296. ; Parameters:   r0-> window handle
  297. ;               r1-> titledata block
  298. ; Returns:      none, or VS and r0 if error
  299. ; *******************************************************************
  300. .swi_titledata
  301.    STMFD   (sp)!,{r0-r4,link}            ; Stack registers
  302.    BL      check_r0_valid                ; is the window handle valid ?
  303.    BVS     $exit                         ; if not, exit with error
  304.    BIC     r0,r0,#1                      ; clear b0
  305.                                          ; **** RO Specific bit ****
  306.    LDR     link,[r12]                    ; read offset for RO version
  307.    ADD     r0,r0,link                    ; and add it to our pointer
  308.                                          ; **** RO Specific bit ****
  309.    LDMIA   r1,{r2-r4}                    ; read 12 bytes
  310.    ADD     r1,r0,#72+72                  ; find the title data address
  311.    STMIA   r1,{r2-r4}                    ; store in block
  312.    BL      redraw_tools                  ; redraw the whole window
  313. $exit
  314.    XLDMFD  (sp)!,{r0-r4,pc}              ; Return from call
  315.  
  316. ; *******************************************************************
  317. ; Subroutine:   swi_windowflags
  318. ; Description:  Change the window flags
  319. ; Parameters:   r0-> window handle
  320. ;               r1 = BIC value
  321. ;               r2 = EOR value
  322. ; Returns:      none, or VS and r0 if error
  323. ; *******************************************************************
  324. .swi_windowflags
  325.    STMFD   (sp)!,{r0-r3,link}            ; Stack registers
  326.    BL      check_r0_valid                ; is the window handle valid ?
  327.    BVS     $exit                         ; if not, exit with error
  328.    BIC     r0,r0,#1                      ; clear b0
  329.                                          ; **** RO Specific bit ****
  330.    LDR     link,[r12]                    ; read offset for RO version
  331.    ADD     r0,r0,link                    ; and add it to our pointer
  332.                                          ; **** RO Specific bit ****
  333.    LDR     r3,[r0,#72+28]                ; read the current settings
  334.    BIC     r3,r3,r1                      ; clear bits specified
  335.    EOR     r3,r3,r2                      ; and invert those others wanted
  336.    STR     r3,[r0,#72+28]                ; store back in block
  337.    BL      redraw_open                   ; redraw the window by opening it
  338. $exit
  339.    XLDMFD  (sp)!,{r0-r3,pc}              ; Return from call
  340.  
  341. ; *******************************************************************
  342. ; Subroutine:   redraw_tools
  343. ; Description:  Redraw just the tool bars
  344. ; Parameters:   r0-> window handle (b0 clear)
  345. ; Returns:      none
  346. ; *******************************************************************
  347. .redraw_tools
  348.    STMFD   (sp)!,{r0-r6,link}            ; Stack registers
  349.    MOV     r6,r0                         ; use r5 as base of block
  350.                                          ; **** RO Specific bit ****
  351.                                          ; only needed because we've already
  352.                                          ; added the offset on...
  353.    LDR     r5,[r12]                      ; read the offset for 'far' blocks
  354.    SUB     r5,r0,r5                      ; and reduce it
  355.                                          ; **** RO Specific bit ****
  356. ; title bar
  357.    LDR     r1,[r5,#28]                   ; left of window (inc tools)
  358.    LDR     r2,[r6,#72+12]                ; top of window (exc tools)
  359.    LDR     r3,[r5,#36]                   ; right of window (inc tools)
  360.    LDR     r4,[r5,#40]                   ; top of window (inc tools)
  361.    XSWI    "XWimp_ForceRedraw",-1        ; redraw whole window
  362. ; right scroll bar
  363.    LDR     r1,[r6,#72+8]                 ; right of window (exc tools)
  364.    LDR     r2,[r5,#32]                   ; bottom of window (inc tools)
  365.    LDR     r3,[r5,#36]                   ; right of window (inc tools)
  366.    LDR     r4,[r5,#40]                   ; top of window (inc tools)
  367.    XSWI    "XWimp_ForceRedraw",-1        ; redraw whole window
  368. ; bottom scroll bar
  369.    LDR     r1,[r5,#28]                   ; left of window (inc tools)
  370.    LDR     r2,[r5,#32]                   ; bottom of window (inc tools)
  371.    LDR     r3,[r5,#36]                   ; right of window (inc tools)
  372.    LDR     r4,[r6,#72+4]                 ; bottom of window (exc tools)
  373.    XSWI    "XWimp_ForceRedraw",-1        ; redraw whole window
  374.    XLDMFD  (sp)!,{r0-r6,pc}              ; Return from call
  375.  
  376. ; *******************************************************************
  377. ; Subroutine:   redraw_window
  378. ; Description:  Redraw the entire window
  379. ; Parameters:   r0-> window handle (b0 clear)
  380. ; Returns:      none
  381. ; *******************************************************************
  382. .redraw_window
  383.    STMFD   (sp)!,{r0-r4,link}            ; Stack registers
  384.  
  385.                                          ; **** RO Specific bit ****
  386.                                          ; only needed because we've already
  387.                                          ; added the offset on...
  388.    LDR     link,[r12]                    ; read the offset for 'far' blocks
  389.    SUB     r0,r0,link                    ; and reduce it
  390.                                          ; **** RO Specific bit ****
  391.  
  392.    LDR     r1,[r0,#28]                   ; left of window (inc tools)
  393.    LDR     r2,[r0,#32]                   ; bottom of window (inc tools)
  394.    LDR     r3,[r0,#36]                   ; right of window (inc tools)
  395.    LDR     r4,[r0,#40]                   ; top of window (inc tools)
  396.    XSWI    "XWimp_ForceRedraw",-1        ; redraw whole window
  397.    XLDMFD  (sp)!,{r0-r4,pc}              ; Return from call
  398.  
  399. ; *******************************************************************
  400. ; Subroutine:   redraw_open
  401. ; Description:  Redraw the window by re-opening it
  402. ; Parameters:   r0-> window block (b0 unset)
  403. ; Returns:      none
  404. ; *******************************************************************
  405. .redraw_open
  406. #Cond Of AllowExternal
  407.    STMFD   (sp)!,{r0-r3,link}            ; Stack registers
  408.    REM     "Sending message to open window"
  409.    XBL     claim,36                      ; claim space for block
  410.    MOV     r1,r0                         ; r1 = claimed block
  411.    LDR     r0,[sp]                       ; re-read window block
  412.  
  413.                                          ; **** RO Specific bit ****
  414.                                          ; only needed because we've already
  415.                                          ; added the offset on...
  416.    LDR     link,[r12]                    ; read the offset for 'far' blocks
  417.    SUB     r0,r0,link                    ; and reduce it
  418.                                          ; **** RO Specific bit ****
  419.  
  420.    ADD     r2,r0,#1                      ; re-assert window handle
  421.    STR     r2,[r1]                       ; store in claimed block
  422.    SWI     "XWimp_GetWindowState"        ; read current state
  423.    XSWI    "XWimp_SendMessage",2         ; send the message to open window
  424.    XBL     release,r1                    ; release the space
  425.    LDR     r0,[sp]                       ; re-read window block
  426.  
  427.                                          ; **** RO Specific bit ****
  428.                                          ; only needed because we've already
  429.                                          ; added the offset on...
  430.    LDR     link,[r12]                    ; read the offset for 'far' blocks
  431.    SUB     r0,r0,link                    ; and reduce it
  432.                                          ; **** RO Specific bit ****
  433.  
  434.    BL      redraw_tools                  ; and redraw the tools too
  435.    LDMFD   (sp)!,{r0-r3,pc}              ; Return from call
  436. #Cond Else
  437.    STMFD   (sp)!,{r0-r1,link}            ; Stack registers
  438.    XBL     claim,36                      ; claim space for block
  439.    MOV     r1,r0                         ; r1 = claimed block
  440.    LDR     r0,[sp]                       ; re-read window block
  441.  
  442.                                          ; **** RO Specific bit ****
  443.                                          ; only needed because we've already
  444.                                          ; added the offset on...
  445.    LDR     link,[r12]                    ; read the offset for 'far' blocks
  446.    SUB     r0,r0,link                    ; and reduce it
  447.                                          ; **** RO Specific bit ****
  448.  
  449.    ADD     r0,r0,#1                      ; re-assert r0
  450.    STR     r0,[r1]                       ; store in claimed block
  451.    SWI     "XWimp_GetWindowState"        ; read current state
  452.    SWI     "XWimp_OpenWindow"            ; open the window
  453.    XBL     release,r1                    ; release the space
  454.    LDR     r0,[sp]                       ; re-read window block
  455.  
  456.                                          ; **** RO Specific bit ****
  457.                                          ; only needed because we've already
  458.                                          ; added the offset on...
  459.    LDR     link,[r12]                    ; read the offset for 'far' blocks
  460.    SUB     r0,r0,link                    ; and reduce it
  461.                                          ; **** RO Specific bit ****
  462.  
  463.    BL      redraw_tools                  ; redraw the tools too
  464.    LDMFD   (sp)!,{r0-r1,pc}              ; Return from call
  465. #Cond End
  466.  
  467. #library "Memory",claim.release
  468. #Here libraries
  469. #Post
  470. #Run <CODE>
  471.